package cn.net.wangyixinwen.mvvm.activity;

import android.view.LayoutInflater;

import cn.net.wangyixinwen.databinding.ActivityGoodsDetailsBinding;
import cn.net.wangyixinwen.databinding.ActivityNewsDetailsBinding;
import cn.net.wangyixinwen.databinding.ActivityVideoDetailsBinding;
import cn.net.wangyixinwen.mvvm.vm.BaseViewModel;
import cn.net.wangyixinwen.mvvm.vm.GoodsDetailsVM;
import xyz.doikki.videocontroller.StandardVideoController;

public class VideoDetailsActivity extends BaseActivity {

    private ActivityVideoDetailsBinding viewBinding;

    @Override
    protected BaseViewModel viewModel() {
        return null;
    }

    @Override
    protected void initView() {
        viewBinding = ActivityVideoDetailsBinding.inflate(LayoutInflater.from(this));
        setContentView(viewBinding.getRoot());
        viewBinding.titleBar.getLeftView().setOnClickListener(v -> finish());
        viewBinding.player.setUrl(getIntent().getStringExtra("url"));
        StandardVideoController controller = new StandardVideoController(this);
        controller.addDefaultControlComponent("详情", false);
        viewBinding.player.setVideoController(controller); //设置控制器
        viewBinding.player.start(); //开始播放，不调用则不自动播放

    }

    @Override
    protected void onPause() {
        super.onPause();
        viewBinding.player.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        viewBinding.player.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        viewBinding.player.release();
    }


    @Override
    public void onBackPressed() {
        if (!viewBinding.player.onBackPressed()) {
            super.onBackPressed();
        }
    }

}
